package com.woniu.controller;


import java.util.List;


import com.github.pagehelper.PageInfo;
import com.woniu.dto.PageData;
import com.woniu.entity.Customer;
import com.woniu.service.ICustomerService;
import com.woniu.utils.ResData;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 客户建档Controller
 *
 * @author lisong
 * @date 2024-04-08
 */
@RestController
public class CustomerController {
    @Autowired
    private ICustomerService customerService;

    /**
     * 查询客户建档列表
     */
    @RequestMapping("/queryCustomer")
     public ResData queryCustomer(@RequestBody PageData<Customer> pageData) {
        PageInfo<Customer> customerPageInfo = customerService.selectCustomerList(pageData);
        return ResData.success(customerPageInfo);
    }


    /**
     * 新增客户建档
     */
    @RequestMapping("addCustomer")
    public ResData addCustomer(@RequestBody Customer customer) {
        int addCustomer = customerService.insertCustomer(customer);
        return ResData.success(addCustomer);
    }

    /**
     * 修改客户建档
     */
    @RequestMapping("updateCustomer")
    public ResData updateCustomer(@RequestBody Customer customer) {
        int updateCustomer = customerService.updateCustomer(customer);
        return ResData.success(updateCustomer);
    }

    /**
     * 删除客户建档
     */
    @RequestMapping("/deleteCustomer/{id}")
    public ResData deleteResident(@PathVariable Integer id) {
        int deleteCustomerById = customerService.deleteCustomerById(Long.valueOf(id));
        return ResData.success(deleteCustomerById);
    }


    /**
     * 选择框使用，查询用户的id和姓名
     */

    @RequestMapping("/queryAllCustomers")
    public ResData queryAllCustomers() {
        List<Customer> allCustomers = customerService.queryAllCustomers();
        return ResData.success(allCustomers);
    }

}
